package com.lct.demo;

import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        /**
         * 密码加密：对密码中的每位数都加5再对10取余，最后所有顺序反转
         * 设计加密程序
         */
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入加密前的四位数字");
        int number = sc.nextInt();
        System.out.println("加密后的结果为" + encryption(number));
    }

    public static int encryption(int number){
        int password = 0;
        int[] wei = new int[4];
        for (int i = 0; i < wei.length; i++) {
            wei[i] = number % 10;
            number /= 10;
        }

        int tmp = 1000;
        for (int i = 0; i < wei.length; i++) {
            wei[i] = ((wei[i] + 5) % 10) * tmp;
            tmp /= 10;
            password += wei[i];
        }
        return password;
    }
}
